package br.com.amigooo.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.amigooo.model.Role;
import br.com.amigooo.repository.RoleImpl;

/**
 * Servlet implementation class CreateServlet
 */
public class CreateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public CreateServlet() {
        RoleImpl roleImpl = new RoleImpl();
        Role role = roleImpl.getRole("ROLE_ADMIN");
        
        if(role == null){
        	System.out.println("Criando papéis");
        	
        	role = new Role();
        	role.setName("ROLE_ADMIN");
        	role.setDescription("Permissões de administrador.");
        	roleImpl.save(role);
        	
        	role = new Role();
        	role.setName("ROLE_COMPANY");
        	role.setDescription("Permissões de estabelecimento.");
        	roleImpl.save(role);
        	
        	role = new Role();
        	role.setName("ROLE_USER");
        	role.setDescription("Permissões de usuário comum.");
        	roleImpl.save(role);
        }else{
        	System.out.println("Papéis já criados");
        }
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
